class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
 }

public class Test {
    public int count = 0;
    public int ans = 0;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        dfs(root);
        return ans;
    }
    public void dfs(TreeNode root) {
        if(root == null || count == 0) return;

        dfs(root.left);
        if(count == 0) return;

        ans = root.val;
        count--;
        if(count == 0) return;

        dfs(root.right);
    }
    public static void main(String[] args) {

    }
}
